package com.feisi.dao;

import com.feisi.domain.Focus;
import com.feisi.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface FocusDao {

    /**
     * 新增关注
     * @param focus
     */
    @Insert("insert into focus values(#{id},#{fo_be_id},#{fo_u_id})")
    void saveFocus(Focus focus);


    /**
     * 删除关注
     * @param focus
     */
    @Delete("delete from focus where fo_be_id=#{fo_be_id} and fo_u_id=#{fo_u_id}")
    void deleteFocus(Focus focus);



    /**
     * 查询 我的关注 的总数
     * @param userid
     * @return
     */
    @Select("select count(*)  from focus f , user u where f.fo_u_id=#{userid} and f.fo_be_id=u.id")
    Integer FocusTotalByUserid(@Param("userid") Integer userid);

    /**
     * 查询我的关注
     * 返回多个用户
     * @param userid
     * @param page
     * @param limit
     * @return
     */
    @Select("select u.*  from focus f , user u where f.fo_u_id=#{userid} and f.fo_be_id=u.id limit #{page},#{limit}")
    List<User> findByUserid(@Param("userid") Integer userid, @Param("page") Integer page, @Param("limit") Integer limit);


    /**
     * 查看有没有相同的关注,
     * 大于0就是有相同的,等于0就是没有相同的关注
     * @param focus
     * @return
     */
    @Select("select count(*) from focus where fo_be_id=#{fo_be_id} and fo_u_id=#{fo_u_id}")
    Integer findByUidAndBeid(Focus focus);
}
